package com.SouthernWall_404.AgeDust.Client.Gui.Screen.EditScreen;

import com.SouthernWall_404.AgeDust.Client.Gui.Screen.AttributeScreen;
import com.SouthernWall_404.AgeDust.Client.Gui.Screen.CharacterScreen;
import com.SouthernWall_404.AgeDust.Common.API.Info.AttributesInfo;
import com.SouthernWall_404.AgeDust.Common.API.Info.CharacterInfo;
import com.SouthernWall_404.AgeDust.Common.Network.C2S.CharacterScreenClientPacket;
import com.SouthernWall_404.AgeDust.Common.Network.ModChannels;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import com.SouthernWall_404.AgeDust.Common.API.Enum.sexEnum;
import com.SouthernWall_404.AgeDust.Common.API.Enum.raceEnum;

public class CharacterEditScreen extends CharacterScreen {

    public CharacterEditScreen(Component component,String name,sexEnum sex,raceEnum raceEnum,int age,AttributesInfo attributesInfo) {
        super(component,name,sex,raceEnum,age,attributesInfo);

    }


    @Override
    public void setNameActive() {
        super.setNameActive();
        this.nameEditBox.active=true;
    }


    @Override
    public void tick() {
        super.tick();
        this.ageEditBox.setValue(this.age_toChange);
    }

    @Override
    public void onAgeStringChanged(String string)
    {
        if(this.race==raceEnum.human)
        {
            if(string!="")
            {
                if(Integer.parseInt(string)<120)
                {
                    this.age_toChange=string;
                }
                else
                {
                    this.age_toChange="120";
                    //this.ageEditBox.setValue(this.age_toChange);
                }
            }
            else
            {
                this.age_toChange="1";
            }


        }

    }

    @Override
    public void setAgeActive() {
        super.setNameActive();
        this.ageEditBox.active=true;
    }


    @Override
    public void onSexClick()
    {
        switch (sex)
        {
            case male -> sex=sexEnum.female;
            case female -> sex=sexEnum.male;
        }

        addSex();
    }

    @Override
    public void onRaceClick()
    {

        addRace();
    }


    @Override
    public void addComfirmButton() {
        super.addComfirmButton();
        int l=100;
        int h=20;
        int n1 = this.width/5*3+GAP;
        int n2 = this.height/2+30;

        comfirmButton.setHeight(h);
        comfirmButton.setWidth(l);
        comfirmButton.setPosition(n1,n2+h/2*3+9);

        addRenderableWidget(comfirmButton);
    }

    @Override
    public void save() {
        super.save();
        CharacterInfo characterInfo=new CharacterInfo(this.name_toChange,sex,race,Integer.parseInt(this.age_toChange));
        AttributesInfo attributesInfo1=this.attributesInfo;

        ModChannels.sendToServer(new CharacterScreenClientPacket(characterInfo,attributesInfo1));
        //this.onClose();
        Minecraft.getInstance().setScreen(new AttributeScreen(Component.literal(""),characterInfo,attributesInfo1));
    }

}
